package com.huawei.petapp2.constant;

import java.io.Serializable;

public class
HttpAddress {
    private static String[] args;
    final private static String userAddress="user";
    final private static String petshowAddress="petshow";//宠物图片展示地址
    final private static String searchhistoryAddress="searchhistory";//历史记录搜索地址
    final private static String searchGoods="storeitem";//商品操作

    final private static String category="index";//商品类别操作

    final private static String product="product";//商品类别操作

    final private static String useraddress="useraddr";//收获地址操作

    final private static String storeaddress="store";//店铺id

    public static String user(){
        return userAddress;
    }

    public static String petshow(){
        return petshowAddress;
    }

    public static String searchhistory(){return searchhistoryAddress;}

    public static String searchGoods(){return searchGoods;}

    public static String Category(){return category;}

    public static String UserAddress(){
        return useraddress;
    }

    public static String detailProduct(){
        return product;
    }

    public static String Store(){
        return storeaddress;
    }

    /**
     *
     * @param address 首地址 例如：“user”
     * @param method 地址中的方法  例如： “insert”
     * @return
     */
    public static String[] get(String address,String method){
        switch (method){
            case "login":args=getLoginAddress();
                break;
            case "insert":args=getInsertAddress(address);//插入新用户
                break;
            case "list":args=getListAddress(address);
                break;
            case "show":args=getShowAddress(address);
                break;
            case "listDesc":args=getSearchHistory(address);//按降序获取搜索地址
                break;
            case "deleteHistory":args=deleteAllHistory(address);//删除所有历史数据
                break;
            case "category-list":args=getCategory(address);//获取所有的分类
                break;
            case "list-recommends":args=getRecomments(address);//获取所有的首页新品推荐
                break;
            case "listAll":args=getAllStore(address);//获取所有的首页新品推荐
                break;
            case  "test":args=getCart(address);
                break;

        }
        return args;
    }
    /**
     *采用方法重载，分别处理两种情况，带id和不带id
     * @param address 首地址 例如：“user”
     * @param method 地址中的方法  例如： “delete”
     * @param id id则为相应参数  delete后的id参数
     * @return
     */
    public static String[] get(String address,String method,Serializable id){
        switch (method){
            case "delete":args=getDeleteAddress(address,id);
                break;
            case "line":args=getLineAddress(address,id);
                break;
            case "searchHistory":args=searchHistory(address);
                break;

            case "delAddr":args=delUserAddress(address, (Integer) id);//删除用户的地址
                break;
            case "getComAddr":args=getCommentUserAddress(address, (Integer) id);//获取用户的默认地址
                break;

            case "detail-info":args=getProsuct(address, (Integer) id);//获取用户的默认地址
                break;

            case "store-list":args=getStore(address, (Integer) id);//获取用户的默认地址
                break;

        }
        return args;
    }

    public static String[]get(String address,String method,int userId,String token)
    {
        switch (method) {
            case "getAddr":args=getUserAddress(address, (Integer) userId,token);//获取用户的所有地址
                break;
        }
        return args;

    }


    public static String[] get(String address,String method,String password,String username){
        switch (method){
            case "login":args=login(address,password,username);
                break;
        }
        return args;
    }



    public static String[] get(String address,String method,String string){
        switch (method){
            //根据用户名获取password
            case "finduserName":args=getUserName(address,string);
                break;

            case "search":args=getKeywordHis(address,string);//根据搜索内容查看历史是否存在
                break;

            case "searchlist":args=searchgoods(address,string);//根据商品名称搜索商品
                break;
        }
        return args;
    }

    public static String[] get(String address,String method,String string,Integer userid) {
        switch (method) {

            case "inserthistory":
                args = setKeywordHis(address, string, userid);//插入根据用户id搜索历史
                break;
            case "getMaxHistory":args=getMaxHistory(address,string,userid);//最多查询多少条数据
                break;
        }
        return args;
    }

    public static String[] get(String address,String method,Integer userid,Integer addrid) {
        switch (method) {

            case "updateCommentAddr":
                args = getCommentAddress(address, userid, addrid);//更新为默认地址
                break;
        }
        return args;
    }

    public static String[] get(String address,String method,Integer userid,Integer addrid,String receiverName,String receiverMobile,
                               String province,String city,String area,
                               String addr,String postCode ) {//更新用户地址
        switch (method) {

            case "updateAddr":
                args = getUpdateAddress(address, userid, addrid,receiverName,receiverMobile,province,city,area,addr,postCode);//更新为默认地址
                break;
            case "insertAddr":
                args = getUpdateAddress(address, userid, 0,receiverName,receiverMobile,province,city,area,addr,postCode);//更新为默认地址
                break;
        }
        return args;
    }

    private static String[] getLoginAddress(){
        args=new String[]{userAddress,"login"};
        return args;
    }



    private static String[] getInsertAddress(String address){
        args=new String[]{address,"insert"};
        return args;
    }

    private static String[] getCart(String address){
        args=new String[]{address,"test"};
        return args;
    }

    private static String[] getDeleteAddress(String address, Serializable id){
        args=new String[]{address,"delete", String.valueOf(id)};
        return args;
    }
    private static String[] getUserName(String address, String userName){//根据用户名获取password
        args=new String[]{address,"finduserName", String.valueOf(userName)};
        return args;
    }
    private static String[] getKeywordHis(String address, String keyword){//根据搜索内容名获取搜索内容是否存在
        args=new String[]{address,"search", String.valueOf(keyword)};
        return args;
    }

    private static String[] setKeywordHis(String address, String keyword,int userid){//根据搜索内容插入搜索历史
        args=new String[]{address,"inserthistory", String.valueOf(keyword), String.valueOf(userid)};
        return args;
    }

    private static String[] login(String address, String password,String username){//根据搜索内容插入搜索历史
        args=new String[]{address,"login", String.valueOf(password), String.valueOf(username)};
        return args;
    }

    private static String[] searchHistory(String address){
        args=new String[]{address,"searchHistory"};
        return args;
    }

    private static String[] getCategory(String address){
        args=new String[]{address,"category-list"};
        return args;
    }

    private static String[] getRecomments(String address){
        args=new String[]{address,"list-recommends"};
        return args;
    }

    private static String[] getAllStore(String address){
        args=new String[]{address,"listAll"};
        return args;
    }

    private static String[] getUserAddress(String address, Integer userId, String token){
        args=new String[]{address,"list", String.valueOf(userId),token};//获取用户的所有地址
        return args;
    }

    private static String[] delUserAddress(String address,Integer adddrId){
        args=new String[]{address,"delete", String.valueOf(adddrId)};
        return args;
    }

    private static String[] getCommentUserAddress(String address,Integer adddrId){
        args=new String[]{address,"getComAdr", String.valueOf(adddrId)};
        return args;
    }

    private static String[] getProsuct(String address,Integer adddrId){
        args=new String[]{address,"detail-info", String.valueOf(adddrId)};
        return args;
    }

    private static String[] getStore(String address,Integer storeId){
        args=new String[]{address,"list", String.valueOf(storeId)};
        return args;
    }

    private static String[] getMaxHistory(String address, String keyword,int num){//最多查询多少条历史
        args=new String[]{address,"getMaxHistory", String.valueOf(keyword),String.valueOf(num)};
        return args;
    }

    private static String[] deleteAllHistory(String address){//删除所有记录
        args=new String[]{address,"getMaxHistory"};
        return args;
    }

    private static String[] searchgoods(String address,String good_name)//查询商品
    {
        args=new String[]{address,"searchlist",good_name};
        return args;
    }

    private static String[] getCommentAddress(String address,Integer userId,Integer addrId){
        args=new String[]{address,"update", String.valueOf(userId), String.valueOf(addrId)};
        return args;
    }

    private static String[] getUpdateAddress(String address,Integer userId,Integer addrId,String receiverName,String receiverMobile,
                                             String province,String city,String area,
                                             String addr,String postCode){
        args=new String[]{
                address,"insert", String.valueOf(userId), String.valueOf(addrId),receiverName,receiverMobile,
                province,city,area,addr,postCode
        };
        return args;
    }

    private static String[] getLineAddress(String address, Serializable id){
        args=new String[]{address,"line", String.valueOf(id)};
        return args;
    }

    private static String[] getListAddress(String address){
        args=new String[]{address,"list"};
        return args;
    }

    private static String[] getShowAddress(String address){
        args=new String[]{address,"show"};
        return args;
    }

    private static String[] getSearchHistory(String address){
        args=new String[]{address,"listDesc"};
        return args;
    }
}

